//
//  Doctor_listTableViewController.m
//  International_Hospital
//
//  Created by 李建强 on 16/7/7.
//  Copyright © 2016年 LiYiLin. All rights reserved.
//

#import "Doctor_listTableViewController.h"
#import "NetWorkTool.h"
#import "DoctorListModel.h"
#import "DoctorInfo_ViewController.h"
#import "DoctorListCell.h"
#import <UIImageView+WebCache.h>



@interface Doctor_listTableViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong)NSArray<DoctorListModel*>*dataArray;
@property (nonatomic,strong)UITableView *tableView;

//@property (nonatomic,strong)DoctorInfo_ViewController *doctorInfoVc;
@end

@implementation Doctor_listTableViewController


-(void)setDataArray:(NSArray<DoctorListModel *> *)dataArray{
    
    _dataArray = dataArray;
    [self.tableView reloadData];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    DoctorListModel *model = [[DoctorListModel alloc]init];
    [model dataSuccess:^(NSArray *dataArray) {
        self.dataArray = dataArray;
        
    } error:^{
        [SVProgressHUD setDefaultStyle:SVProgressHUDStyleLight];
        [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
        [SVProgressHUD showErrorWithStatus:@"网络故障!"];
        [SVProgressHUD dismissWithDelay:1];
    }];
    
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.equalTo(self.view);
    }];
    
    self.tableView.delegate =self;
    self.tableView.dataSource =self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerClass:[DoctorListCell class] forCellReuseIdentifier:@"listcell"];
    
}

#pragma mark - tableView数据源方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    
    DoctorListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"listcell" forIndexPath:indexPath];
    cell.model = self.dataArray[indexPath.row];
    return cell;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 120;
}


#pragma mark - tableView代理方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    DoctorInfo_ViewController *doctorInfoVc = [[DoctorInfo_ViewController alloc]init];
    
    doctorInfoVc.doctorName = self.dataArray[indexPath.row].doctor_name;
    doctorInfoVc.imgName = self.dataArray[indexPath.row].doctor_portrait;
    doctorInfoVc.title = @"医生基本信息";
//    [doctorInfoVc.picImageView sd_setImageWithURL:[NSURL URLWithString:self.dataArray[indexPath.row].doctor_portrait]];
    
    
    DoctorListCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    doctorInfoVc.banner = cell.banner;
    
    doctorInfoVc.hospitalName = self.dataArray[indexPath.row].doctor_hospital_name;
    [self.navigationController pushViewController:doctorInfoVc animated:YES];
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}



@end





